package com.horizon.cloud.seckill.dao;

import com.horizon.cloud.seckill.dao.po.SeckillSkuPO;
import feign.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;

@Repository
public interface SeckillSkuDao extends JpaRepository<SeckillSkuPO, Long>,
        JpaSpecificationExecutor<SeckillSkuDao> {
    @Transactional
    @Modifying
    @Query("update SeckillSkuPO g set g.stockCount = g.stockCount-1 " +
            "where g.id = :id")
    int updateStockCountById(@Param("id") Long id);
}
